package com.ruoyi.fengkong.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.fengkong.entity.TFkBusinessCreditSub;
import com.ruoyi.fengkong.service.ITFkBusinessCreditSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 风控公寓授信子Controller
 * 
 * @author wish
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/sub")
public class TFkBusinessCreditSubController extends BaseController
{
    @Autowired
    private ITFkBusinessCreditSubService tFkBusinessCreditSubService;

    /**
     * 查询风控公寓授信子列表
     */
    @PreAuthorize(hasPermi = "fengkong:sub:list")
    @GetMapping("/list")
    public TableDataInfo list(TFkBusinessCreditSub tFkBusinessCreditSub)
    {
        startPage();
        List<TFkBusinessCreditSub> list = tFkBusinessCreditSubService.selectTFkBusinessCreditSubList(tFkBusinessCreditSub);
        return getDataTable(list);
    }

    /**
     * 导出风控公寓授信子列表
     */
    @PreAuthorize(hasPermi = "fengkong:sub:export")
    @Log(title = "风控公寓授信子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFkBusinessCreditSub tFkBusinessCreditSub) throws IOException
    {
        List<TFkBusinessCreditSub> list = tFkBusinessCreditSubService.selectTFkBusinessCreditSubList(tFkBusinessCreditSub);
        ExcelUtil<TFkBusinessCreditSub> util = new ExcelUtil<TFkBusinessCreditSub>(TFkBusinessCreditSub.class);
        util.exportExcel(response, list, "风控公寓授信子数据");
    }

    /**
     * 获取风控公寓授信子详细信息
     */
    @PreAuthorize(hasPermi = "fengkong:sub:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tFkBusinessCreditSubService.selectTFkBusinessCreditSubById(id));
    }

    /**
     * 新增风控公寓授信子
     */
    @PreAuthorize(hasPermi = "fengkong:sub:add")
    @Log(title = "风控公寓授信子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFkBusinessCreditSub tFkBusinessCreditSub)
    {
        return toAjax(tFkBusinessCreditSubService.insertTFkBusinessCreditSub(tFkBusinessCreditSub));
    }

    /**
     * 修改风控公寓授信子
     */
    @PreAuthorize(hasPermi = "fengkong:sub:edit")
    @Log(title = "风控公寓授信子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFkBusinessCreditSub tFkBusinessCreditSub)
    {
        return toAjax(tFkBusinessCreditSubService.updateTFkBusinessCreditSub(tFkBusinessCreditSub));
    }

    /**
     * 删除风控公寓授信子
     */
    @PreAuthorize(hasPermi = "fengkong:sub:remove")
    @Log(title = "风控公寓授信子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tFkBusinessCreditSubService.deleteTFkBusinessCreditSubByIds(ids));
    }
}
